<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>django.conf.urls &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../../../index.html" />
    <link rel="up" title="django" href="../../django.html" />



 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-conf-urls">
            
  <h1>Source code for django.conf.urls</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">importlib</span> <span class="kn">import</span> <span class="n">import_module</span>

<span class="kn">from</span> <span class="nn">django.core.urlresolvers</span> <span class="kn">import</span> <span class="p">(</span><span class="n">RegexURLPattern</span><span class="p">,</span>
    <span class="n">RegexURLResolver</span><span class="p">,</span> <span class="n">LocaleRegexURLResolver</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">django.core.exceptions</span> <span class="kn">import</span> <span class="n">ImproperlyConfigured</span>
<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">six</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;handler400&#39;</span><span class="p">,</span> <span class="s">&#39;handler403&#39;</span><span class="p">,</span> <span class="s">&#39;handler404&#39;</span><span class="p">,</span> <span class="s">&#39;handler500&#39;</span><span class="p">,</span> <span class="s">&#39;include&#39;</span><span class="p">,</span> <span class="s">&#39;patterns&#39;</span><span class="p">,</span> <span class="s">&#39;url&#39;</span><span class="p">]</span>

<span class="n">handler400</span> <span class="o">=</span> <span class="s">&#39;django.views.defaults.bad_request&#39;</span>
<span class="n">handler403</span> <span class="o">=</span> <span class="s">&#39;django.views.defaults.permission_denied&#39;</span>
<span class="n">handler404</span> <span class="o">=</span> <span class="s">&#39;django.views.defaults.page_not_found&#39;</span>
<span class="n">handler500</span> <span class="o">=</span> <span class="s">&#39;django.views.defaults.server_error&#39;</span>


<div class="viewcode-block" id="include"><a class="viewcode-back" href="../../../ref/urls.html#django.conf.urls.include">[docs]</a><span class="k">def</span> <span class="nf">include</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">namespace</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">app_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
        <span class="c"># callable returning a namespace hint</span>
        <span class="k">if</span> <span class="n">namespace</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span><span class="s">&#39;Cannot override the namespace for a dynamic module that provides a namespace&#39;</span><span class="p">)</span>
        <span class="n">urlconf_module</span><span class="p">,</span> <span class="n">app_name</span><span class="p">,</span> <span class="n">namespace</span> <span class="o">=</span> <span class="n">arg</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c"># No namespace hint - use manually provided namespace</span>
        <span class="n">urlconf_module</span> <span class="o">=</span> <span class="n">arg</span>

    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">urlconf_module</span><span class="p">,</span> <span class="n">six</span><span class="o">.</span><span class="n">string_types</span><span class="p">):</span>
        <span class="n">urlconf_module</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="n">urlconf_module</span><span class="p">)</span>
    <span class="n">patterns</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">urlconf_module</span><span class="p">,</span> <span class="s">&#39;urlpatterns&#39;</span><span class="p">,</span> <span class="n">urlconf_module</span><span class="p">)</span>

    <span class="c"># Make sure we can iterate through the patterns (without this, some</span>
    <span class="c"># testcases will break).</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">patterns</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
        <span class="k">for</span> <span class="n">url_pattern</span> <span class="ow">in</span> <span class="n">patterns</span><span class="p">:</span>
            <span class="c"># Test if the LocaleRegexURLResolver is used within the include;</span>
            <span class="c"># this should throw an error since this is not allowed!</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">url_pattern</span><span class="p">,</span> <span class="n">LocaleRegexURLResolver</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                    <span class="s">&#39;Using i18n_patterns in an included URLconf is not allowed.&#39;</span><span class="p">)</span>

    <span class="k">return</span> <span class="p">(</span><span class="n">urlconf_module</span><span class="p">,</span> <span class="n">app_name</span><span class="p">,</span> <span class="n">namespace</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="patterns"><a class="viewcode-back" href="../../../ref/urls.html#django.conf.urls.patterns">[docs]</a><span class="k">def</span> <span class="nf">patterns</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
    <span class="n">pattern_list</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="n">t</span> <span class="o">=</span> <span class="n">url</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="n">prefix</span><span class="p">,</span> <span class="o">*</span><span class="n">t</span><span class="p">)</span>
        <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">RegexURLPattern</span><span class="p">):</span>
            <span class="n">t</span><span class="o">.</span><span class="n">add_prefix</span><span class="p">(</span><span class="n">prefix</span><span class="p">)</span>
        <span class="n">pattern_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">pattern_list</span>

</div>
<div class="viewcode-block" id="url"><a class="viewcode-back" href="../../../ref/urls.html#django.conf.urls.url">[docs]</a><span class="k">def</span> <span class="nf">url</span><span class="p">(</span><span class="n">regex</span><span class="p">,</span> <span class="n">view</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">view</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
        <span class="c"># For include(...) processing.</span>
        <span class="n">urlconf_module</span><span class="p">,</span> <span class="n">app_name</span><span class="p">,</span> <span class="n">namespace</span> <span class="o">=</span> <span class="n">view</span>
        <span class="k">return</span> <span class="n">RegexURLResolver</span><span class="p">(</span><span class="n">regex</span><span class="p">,</span> <span class="n">urlconf_module</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">,</span> <span class="n">app_name</span><span class="o">=</span><span class="n">app_name</span><span class="p">,</span> <span class="n">namespace</span><span class="o">=</span><span class="n">namespace</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">view</span><span class="p">,</span> <span class="n">six</span><span class="o">.</span><span class="n">string_types</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">view</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span><span class="s">&#39;Empty URL pattern view name not permitted (for pattern </span><span class="si">%r</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="n">regex</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">prefix</span><span class="p">:</span>
                <span class="n">view</span> <span class="o">=</span> <span class="n">prefix</span> <span class="o">+</span> <span class="s">&#39;.&#39;</span> <span class="o">+</span> <span class="n">view</span>
        <span class="k">return</span> <span class="n">RegexURLPattern</span><span class="p">(</span><span class="n">regex</span><span class="p">,</span> <span class="n">view</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span></div>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3>Browse</h3>
  <ul>
    
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../../../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="../../index.html">Module code</a>
        
          <ul><li><a href="../../django.html">django</a>
        
        <ul><li>django.conf.urls</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>